
local MainScene = class("MainScene", cc.load("mvc").ViewBase)


function MainScene:sf_frameEvent(eventName, armatureName, animationName)
    print("sf_frameEvent_callback", eventName, armatureName, animationName)
end

function MainScene:sf_animationEvent(eventType, armatureName, animationName)
    print("animationEvent", eventType, armatureName, animationName)
end

function MainScene:onCreate()
    -- add background image
    display.newSprite("HelloWorld.png")
        :move(display.center)
        :addTo(self)

    -- add HelloWorld label
    cc.Label:createWithSystemFont("Hello World", "Arial", 40)
        :move(display.cx, display.cy + 200)
        :addTo(self)




    local factory = db.CCFactory:getInstance()
    factory:setArmaturePath("res/armatures")
    factory:loadDataByName("sf")
    dump(factory, "factory = ")
    local sf = factory:buildArmatureDisplay("armatureName", "sf")
    sf:setPosition(display.center)
    sf:setScale(.5)
    -- 动作速度提升为两倍
    sf:setTimeScale(2)
    self:addChild(sf)
    -- 播放动作normalAttack 100遍
    local animState = sf:getAnimation():gotoAndPlayByFrame("normalAttack", 0, 100)
    -- 或者匿名函数的方式
    --[[
    sf:setFrameEventListener(function(eventName, armatureName, animationName)
    print(eventName, armatureName, animationName)
    end)
    ]]
    sf:setFrameEventListener(self, self.sf_frameEvent)
    sf:setAnimationEventListener(self, self.sf_animationEvent)
    -- 或者匿名函数的方式
    --[[
    sf:setAnimationEventListener(function(eventType, armatureName, animationName)
    print("animationEvent", eventType, armatureName, animationName)
    end)
    ]]
    -- -- 暂停当前动画
    -- animState:stop()
    -- -- 继续当前动画
    -- animState:play()
end

return MainScene
